package cn.ybk.org.service.impl;

import cn.ybk.basic.util.PageList;
import cn.ybk.org.domain.Department;
import cn.ybk.org.mapper.DepartmentMapper;
import cn.ybk.org.query.PageQuery;
import cn.ybk.org.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    // 查询全部数据
    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    // 查询单个数据
    @Override
    public Department findById(Long id) {
        return departmentMapper.findById(id);
    }

    // 添加数据
    @Override
    public void add(Department department) {
        departmentMapper.add(department);

    }

    // 修改数据
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    // 删除数据
    @Override
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public PageList<Department> queryByPage(PageQuery query) {
        Integer totals = departmentMapper.queryByCount(query);
        if (totals <=0 ){
            return new PageList<>(0,new ArrayList<>());
        }
        List<Department> rows = departmentMapper.queryByPage(query);
        return new PageList<>(totals, rows);
    }


}
